﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UCLibrary.UC;

namespace 项目框架
{
    public partial class FrmSignal : Form
    {
        public FrmSignal()
        {
            InitializeComponent();
            ucBtn1.Click += ucBtn_Click;
            ucBtn2.Click += ucBtn_Click;
            ucBtn3.Click += ucBtn_Click;
            ucBtn4.Click += ucBtn_Click;
        }

        private void ucBtn_Click(object sender, EventArgs e)
        {
            UCBtn btn = sender as UCBtn;
            Form frm = null;
            //遍历后改变按钮颜色
            foreach (UCBtn bt in panel1.Controls)
            {
                bt.backgroundColor = Color.DimGray;
            }
            btn.backgroundColor = this.panel2.BackColor;
            switch (btn.TabIndex)
            {
                case 0:
                    frm = new SignalMonitor.FrmInputSignal();
                    break;
                case 1:
                    //frm = frmPlc;
                    break;
                case 2:
                    //frm = new FrmAlarm();
                    break;
                case 3:
                    //frm = new FrmSignal();
                    break;
            }
            //遍历窗体控件后关闭窗体
            foreach (Form fr in this.panel2.Controls)
            {
                    fr.Close();
            }
            this.panel2.Controls.Clear();
            if (frm != null)
            {
                frm.TopLevel = false;
                //frm.Parent = this.panel2;
                frm.Dock = DockStyle.Fill;
                frm.Show();
                this.panel2.Controls.Add(frm);
            }
        }

        private void FrmSignal_Load(object sender, EventArgs e)
        {
            ucBtn_Click(ucBtn1, e);
        }

        private void FrmSignal_FormClosed(object sender, FormClosedEventArgs e)
        {
        }
    }
}
